package com.clothing.dao.impl;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Repository;

import com.clothing.dao.CommentReplyDao;
import com.clothing.entity.CommentReply;
import com.clothing.utils.page.Page;
import com.clothing.utils.page.Pageable;

/**
 * @ClassName: CommentReplyDaoImpl 
 * @Description: TODO(Dao) 
 * @author Charles.Tao 
 * @date 2017年9月6日 下午3:40:20 
 * @version 1.0
 */
@Repository
public class CommentReplyDaoImpl extends BaseDaoImpl<CommentReply, Long> implements CommentReplyDao
{
    @Override
    public Page<CommentReply> myCommentList(Long userId, Pageable pageable)
    {
        CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        CriteriaQuery<CommentReply> criteriaQuery = criteriaBuilder
            .createQuery(CommentReply.class);
        Root<CommentReply> root = criteriaQuery.from(CommentReply.class);
        criteriaQuery.select(root);
        Predicate predicate = criteriaBuilder.or(criteriaBuilder
            .equal(root.get("creator").get("id"), userId), criteriaBuilder
            .equal(root.get("other").get("id"), userId));
        criteriaQuery.where(predicate);
        
        return findPage(criteriaQuery, pageable);
    }
}
